package com.aiti.lulian.strategy.task;

import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.dto.CardUserIncreaseRankDto;
import com.aiti.lulian.entity.CardUserRankTaskHistory;
import com.aiti.lulian.entity.newCard.CardBaseInfo;
import com.aiti.lulian.enums.RankIncreaseTaskStrategyEnum;
import com.aiti.lulian.mapper.CardRankTaskUserCompleteMapper;
import com.aiti.lulian.mapper.newCard.CardPersonalBaseInfoMapper;
import com.aiti.lulian.service.CardUserRankTaskHistoryService;
import com.aiti.lulian.vo.CardRankTaskUserVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import org.springframework.util.StringUtils;

import java.util.List;

public interface RankIncreaseTaskStrategy {
    RankIncreaseTaskStrategyEnum getStrategy();

    void handleTask(CardRankTaskUserVo vo, CardUserIncreaseRankDto dto);

    default List<CardRankTaskUserVo> getCompletedTask(CardUserIncreaseRankDto dto) {
        String cardId = dto.getCardId();
        String type = getStrategy().getType();
        CardRankTaskUserVo vo = new CardRankTaskUserVo();
        vo.setCardId(cardId);
        vo.setType(type);
        CardBaseInfo cardBaseInfo = getBaseInfoMapper().selectById(dto.getCardId());
        String enterpriseId = cardBaseInfo.getEnterpriseId();
        String version = "0";
        if(!StringUtils.isEmpty(enterpriseId)){
            version = "1";
        }
        vo.setVersion( version);
        return getCardRankTaskUserCompleteMapper().currentUserTaskCompleteListByCondition(vo);

    }

    CardRankTaskUserCompleteMapper getCardRankTaskUserCompleteMapper();

    CardPersonalBaseInfoMapper getBaseInfoMapper();

    CardUserRankTaskHistoryService getHisotryService();


    default void increseScore(CardUserIncreaseRankDto dto){
        CardBaseInfo cardBaseInfo = getBaseInfoMapper().selectById(dto.getCardId());
        CardBaseInfo updateCardBaseInfo = new CardBaseInfo();
        updateCardBaseInfo.setBaseId(dto.getCardId());
        updateCardBaseInfo.setCardRankTotalScore(cardBaseInfo.getCardRankTotalScore() + dto.getScore());
        updateCardBaseInfo.setCardRankTaskScore(cardBaseInfo.getCardRankTaskScore() + dto.getScore());
        getBaseInfoMapper().updateById(updateCardBaseInfo);
    }
    default void recordHistory(CardUserIncreaseRankDto dto){
        CardUserRankTaskHistory cardUserRankTaskHistory = new CardUserRankTaskHistory();
        cardUserRankTaskHistory.setType(dto.getType()).setCardId(dto.getCardId()).setUserId(dto.getUserId()).setScore(dto.getScore());
        getHisotryService().save(cardUserRankTaskHistory);
    }

    Message handle(CardUserIncreaseRankDto dto);



}
